package com.naizhuai.util;

import android.content.Context;

import com.naizhuai.network.ClientFactory;
import com.naizhuai.network.Config;
import com.naizhuai.network.entity.ResultResponse;
import com.naizhuai.ui.entity.mainbusiness.TargetSearchLimitedBack;

import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.converter.scalars.ScalarsConverterFactory;
import retrofit2.http.GET;
import retrofit2.http.QueryMap;

/**
 * Created by code_han on 2018/4/13.
 */

public class NetWorkTest {

    public static void getNetWork(Map<String,String> map, Context mContext){
        Retrofit retrofit = new Retrofit.Builder()
                .client(ClientFactory.getInstance(mContext))
                .baseUrl(Config.TEST_ACTION_BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .addConverterFactory(ScalarsConverterFactory.create())
                .build();

        ShopService service = retrofit.create(ShopService.class);

        Call<ResultResponse<TargetSearchLimitedBack>> callShops = service.getShop(map);

        NaizhuAILog.e("getUserList=start");
        callShops.enqueue(new Callback<ResultResponse<TargetSearchLimitedBack>>() {
            @Override
            public void onResponse(Call<ResultResponse<TargetSearchLimitedBack>> call, Response<ResultResponse<TargetSearchLimitedBack>> response) {
                ResultResponse<TargetSearchLimitedBack> result = response.body();
                NaizhuAILog.e("getUserList="+ result.getRes().getSource().toString());
            }

            @Override
            public void onFailure(Call<ResultResponse<TargetSearchLimitedBack>> call, Throwable t) {
                NaizhuAILog.e("getUserList=start="+t.getMessage());
            }

        });
    }


    public interface ShopService {
        @GET(Config.TARGET_SEARCH_USER_DETAILS)
        Call<ResultResponse<TargetSearchLimitedBack>> getShop(@QueryMap Map<String,String> map);
    }

}
